/**
 * Description: 测试竞态条件客户端
 * File: client.c |Time: 2021-07-16 07:54
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define ERR(msg) do {   \
    perror(msg);    \
    printf("err_at: %s:%s %d\n", __FILE__, __func__, __LINE__); \
} while(0)

int main(int argc, const char *argv[])
{
    int ret;
    int number;
    int fd = open("/dev/demo_dev", O_RDWR);
    if (fd < 0) 
    {
        ERR("open");
        return -1;
    }

    while (1)
    {
        ret = read(fd, &number, sizeof(number));
        if (ret < 0) 
        {
            ERR("read");
            sleep(1);
            continue;
        }

        printf("number = %d\n", number);
        sleep(1);
    }

    if (close(fd) < 0) 
    {
        ERR("close");
        return -1;
    }

    return 0;
}


